import unittest
import requests
from unit__002.unit_01.excel_reder import excel
from unit__002.unit_01.excel_write2 import write2
from ddt import ddt, data, unpack

path = r'D:\gao5biji\wenjian\newgw\unit__002\unit_01\data.xlsx'
sheetname = 'Sheet1'
db = excel(path, sheetname)


@ddt
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')
        # 初始化写的对象
        self.w2 = write2(path, sheetname)

    def tearDown(self) -> None:
        print('start case')

    @data(*db.get_data())
    @unpack
    def test_01_login(self, case_ID, case_QZ, case_methon, case_body1, case_bz1, case_body2, case_bz2, case_exp):
        print('*' + case_QZ + '*' + case_methon + '*')
        print(case_body1 + '*' + case_body2 + '*' + case_exp)
        url = 'http://10.59.9.14:7003/api/public/login'
        data = {"username": case_bz1, "password": case_bz2}
        login = requests.post(url=url, json=data)
        print(login.json())
        print(case_ID)
        index = int(str(case_ID[-3:]).lstrip('0'))
        self.w2.write(index + 1, 13, login.json())


if __name__ == '__main__':
    unittest.main()
